package com.zxmr.hospital.info.action;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.zxmr.action.Request;
import com.zxmr.action.Response;
import com.zxmr.action.ResponsePayload;
import com.zxmr.domain.account.Role;
import com.zxmr.domain.account.User;
import com.zxmr.domain.service.UserService;
import com.zxmr.hospital.info.action.dto.EmployeeDTO;
import com.zxmr.navigate.Executor;

public class QueryPersonalInfo extends Executor{

	@Override
	public void execute(Request request, Response response) {
		
		User user = (User)request.getAccount();
		UserService service = new UserService();
		List<Role> roles = service.getAllRole(user);
		
		EmployeeDTO dto = transferUserToDTO(user);
		dto.setRoles(roles);
		
		ResponsePayload payload = new ResponsePayload();
		
		payload.setValue(JSON.toJSONString(dto));
		response.setPayload(payload);
	}

	private EmployeeDTO transferUserToDTO(User user)
	{
		EmployeeDTO dto = new EmployeeDTO();
		dto.setName(user.getName());
		dto.setDisplay(user.getDisplay());
		dto.setPassword(user.getPassword());
		dto.setEmail(user.getEmail());
		dto.setAge(user.getAge());
		dto.setCell(user.getCell());
		dto.setCollege(user.getCollege());
		dto.setEducation(user.getEducation());
		dto.setSalary(user.getSalary());
		dto.setSex(user.getSex());
		dto.setStatus(user.getStatus());
		return dto;
	}
}
